<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8"
         contentType="text/html;charset=utf-8" %>
<%@ include file="/common/taglibs.jsp" %>
<head>
    <title>订单列表</title>
</head>
<body>
<div id="wrapper">
    <c:set var="left">productOrder</c:set>
    <%@ include file="/include/left/financial.jsp" %>

    <s:action name="product-order!search" var="productOrderList" executeResult="false">
        <s:param name="query.enabled">true</s:param>
        <s:param name="query.order">addTime</s:param>
        <s:param name="query.desc">true</s:param>
        <s:param name="query.pagesize">10</s:param>
        <c:if test="${param.startAddTime!=null && param.startAddTime!=''}">
            <s:param name="query.startAddTime">${param.startAddTime} 00:00:00</s:param>
        </c:if>
        <c:if test="${param.endAddTime!=null && param.endAddTime!=''}">
            <s:param name="query.endAddTime">${param.endAddTime} 23:59:59</s:param>
        </c:if>
    </s:action>

    <div id="page-wrapper" class="gray-bg">

        <div class="row wrapper border-bottom white-bg page-heading">
            <div class="col-lg-10">
                <h2>订单列表</h2>
                <ol class="breadcrumb">
                    <li>
                        <a href="${ctx}/productOrder/">财务管理</a>
                    </li>
                    <li>
                        <a>订单管理</a>
                    </li>
                    <li class="active">
                        <strong>订单列表</strong>
                    </li>
                </ol>
            </div>
        </div>

        <div class="wrapper wrapper-content animated fadeInRight ecommerce">
            <form action="${ctx}/productOrder/" method="get" class="shaix">
                <div class="ibox-content m-b-sm border-bottom">
                    <div class="row">
                        <div class="col-sm-4">
                            <div class="form-group">
                                <label class="control-label" for="title">订单号</label>
                                <input type="text" id="title" name="query.no" value="${query.no}"
                                       placeholder="请输入订单号"
                                       class="form-control">
                            </div>
                        </div>
                        <%--<div class="col-sm-2">--%>
                        <%--<div class="form-group">--%>
                        <%--<label class="control-label" for="source">来源</label>--%>
                        <%--<input type="text" id="source" name="query.source" value="${query.source}"--%>
                        <%--placeholder="请输入订单来源"--%>
                        <%--class="form-control">--%>
                        <%--</div>--%>
                        <%--</div>--%>


                        <div class="col-sm-2">
                            <div class="form-group">
                                <label class="control-label" for="select">自定义时间</label>
                                <select id="select" class="form-control" name="timeType">
                                    <option value="3">自定义时间</option>
                                    <option value="0" <c:if test="${param.timeType==0}">selected</c:if>>今天</option>
                                    <option value="1" <c:if test="${param.timeType==1}">selected</c:if>>最近一周</option>
                                    <option value="2" <c:if test="${param.timeType==2}">selected</c:if>>最近一个月</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-2">
                            <div class="form-group">
                                <label class="control-label" for="date_before">开始时间</label>
                                <input type="text" id="date_before" name="startAddTime" class="form-control"
                                       placeholder="开始时间" value="${param.startAddTime}">
                            </div>
                        </div>
                        <div class="col-sm-2">
                            <div class="form-group">
                                <label class="control-label" for="date_after">结束时间</label>
                                <input type="text" id="date_after" name="endAddTime" class="form-control"
                                       placeholder="结束时间" value="${param.startAddTime}">
                            </div>
                        </div>

                        <div class="col-sm-2">
                            <div class="form-group">
                                <label class="control-label" for="status">状态</label>
                                <select name="query.state" id="status" class="form-control">
                                    <option value="">请选择状态</option>
                                    <option value="0" <c:if test="${query.state==0}">selected</c:if>>待付款</option>
                                    <option value="1" <c:if test="${query.state==1}">selected</c:if>>已完成</option>
                                    <option value="-1" <c:if test="${query.state==-1}">selected</c:if>>已取消</option>
                                    <option value="2" <c:if test="${query.state==2}">selected</c:if>>待联系</option>
                                    <option value="3" <c:if test="${query.state==3}">selected</c:if>>处理中</option>
                                </select>
                            </div>
                        </div>

                        <div class="col-sm-12">
                            <input type="submit" class="btn btn-sm btn-primary" value="查询"/>
                        </div>
                    </div>

                </div>
            </form>


            <div class="row">
                <div class="col-lg-12">
                    <div class="ibox">
                        <div class="ibox-content">

                            <table class="footable table table-striped table-hover toggle-arrow-tiny default breakpoint footable-loaded"
                                   data-page-size="15">
                                <thead>
                                <tr>

                                    <th data-toggle="true"
                                        class="footable-visible footable-first-column footable-sortable">添加时间<span
                                            class="footable-sort-indicator"></span></th>
                                    <th data-hide="phone" class="footable-visible footable-sortable">订单号<span
                                            class="footable-sort-indicator"></span></th>
                                    <th data-hide="phone" class="footable-visible footable-sortable">联系人<span
                                            class="footable-sort-indicator"></span></th>
                                    <th data-hide="phone" class="footable-visible footable-sortable">联系电话<span
                                            class="footable-sort-indicator"></span></th>
                                    <%--<th data-hide="all" class="footable-sortable">商品详情<span class="footable-sort-indicator"></span></th>--%>
                                    <th data-hide="all" class="footable-sortable">总计价格<span
                                            class="footable-sort-indicator"></span></th>
                                    <th data-hide="all" class="footable-sortable">订单状态<span
                                            class="footable-sort-indicator"></span></th>
                                    <th class="text-right footable-visible footable-last-column"
                                        data-sort-ignore="true">操作
                                    </th>

                                </tr>
                                </thead>
                                <tbody>

                                <s:iterator value="%{#productOrderList.productOrders}" status="rowStatus"
                                            var="productOrder">
                                    <tr class="footable-even" style="">
                                        <td class="footable-visible">
                                            <s:date name="%{addTime}" format="yyyy-MM-dd HH:mm"></s:date>
                                        </td>
                                        <td class="footable-visible">${no}</td>
                                        <td class="footable-visible">${addrName}</td>
                                        <td class="footable-visible">${addrMobile}</td>
                                        <td class="footable-visible">${price}</td>
                                        <td class="footable-visible">${statements}</td>
                                        <td class="text-right footable-visible footable-last-column">
                                            <div class="btn-group">
                                                <c:if test="${refundState==0}">
                                                    <c:if test="${state==2}">
                                                        <button class="btn-info btn btn-xs" onclick="contact('${id}');">已联系,通知量房</button>
                                                        <button class="btn-danger btn btn-xs" onclick="cancleOrder('${id}');">取消订单</button>
                                                    </c:if>
                                                    <c:if test="${state==3}">
                                                        <c:if test="${handleState==0}">
                                                            <button class="btn-info btn btn-xs" onclick="waitExecution('${id}');">已量房,准备施工</button>
                                                            <button class="btn-danger btn btn-xs" onclick="addOrder('${id}');">已量房,需补单</button>
                                                        </c:if>
                                                        <c:if test="${handleState==1}">
                                                            <button class="btn-info btn btn-xs" onclick="execution('${id}');">施工完毕,待验收</button>
                                                        </c:if>
                                                    </c:if>
                                                </c:if>
                                                <button class="btn-success btn btn-xs" onclick="orderView('${id}');">详情</button>
                                            </div>
                                        </td>
                                    </tr>

                                </s:iterator>
                                </tbody>


                            </table>
                            <c:set var="href">timeType=${param.timeType}&startAddTime=${param.startAddTime}&endAddTime=${param.endAddTime}&</c:set>
                            <%@ include file="/common/page.jsp" %>
                        </div>
                    </div>
                </div>
            </div>

        </div>

        <%@ include file="/common/footer.jsp" %>

    </div>

</div>

<%@ include file="/common/scripts.jsp" %>
<%@ include file="/common/script/cxcalendar.jsp" %>
<script src="${dll}/api/assets/layer/mobile/layer.js"></script>

<script>

    /**
     * 已联系,通知量房
     */
    function contact(_id) {
        var check = confirm("确定要通知量房吗？");
        if (check) {
            $.ajax({
                url: "${ctx}/product-order!contact.action",
                type: "post",
                data: {
                    id: _id,
                    ifCando: true
                },
                dataType: "json",
                success: function (result) {
                    window.location.reload();
                }
            });
        }
    }

    /**
     * 已联系,取消订单
     */
    function cancleOrder(_id) {
        var check = confirm("确定要取消订单吗？");
        if (check) {
            $.ajax({
                url: "${ctx}/product-order!contact.action",
                type: "post",
                data: {
                    id: _id,
                    ifCando: false
                },
                dataType: "json",
                success: function (result) {
                    window.location.reload();
                }
            });
        }
    }

    /**
     * 待施工 :当联系后,得知不需要补单,则由"待量房"变"已量房"
     */
    function waitExecution(_id) {
        var check = confirm("确定要准备施工吗？");
        if (check) {
            $.ajax({
                url: "${ctx}/product-order!waitExecution.action",
                type: "post",
                data: {
                    id: _id
                },
                dataType: "json",
                success: function (result) {
                    window.location.reload();
                }
            });
        }
    }

    /**
     * 待施工 :当联系后,得知不需要补单,则由"待量房"变"已量房"
     */
    function execution(_id) {
        var check = confirm("施工完毕了吗？");
        if (check) {
            $.ajax({
                url: "${ctx}/product-order!execution.action",
                type: "post",
                data: {
                    id: _id
                },
                dataType: "json",
                success: function (result) {
                    window.location.reload();
                }
            });
        }
    }

    /**
    * 添加补单
    * @param id
    */
    function addOrder(id) {
        $.get("${ctx}/ajax/additionalOrder/add.jsp?id=" + id, function (result) {
            layer.open({
                type: 1,
                area: ['7000px', '5500px'], //宽高
                content: result,
                title: "补单信息"
            });
        });
    }

    /**
    * 订单详情
    */
    function orderView(id) {
        window.location.href = "${ctx}/productOrder/view/"+id;
    }


</script>

<script>
    function ifAddSure(id) {
        var orderName=$("#orderName").val();
        var orderPrice=$("#orderPrice").val();
        if(orderName==null || orderName=='' || orderPrice=='' || orderPrice<=0){
//            layer.msg("请填写全补单信息");
            layer.open({
                content: "请填写全补单信息",
                skin: 'msg',
                time: 2 //2秒后自动关闭
            });
        }else {
            var check = confirm("确定要补单吗？");
            if (check) {
                $.ajax({
                    url: "${ctx}/additional-order!save.action",
                    type: "post",
                    data: {
                        'additionalOrder.productOrder.id': id,
                        'additionalOrder.name': orderName,
                        'additionalOrder.price': orderPrice
                    },
                    dataType: "json",
                    success: function (result) {
                        window.location.reload();
                    }
                });
            }
        }


    }

</script>

</body>

